import {
  BufferGeometry,
  Color,
  Points,
  PointsMaterial,
  Vector2,
  Vector3,
} from 'three';
import View2D from './View2D';

const normalMat = new PointsMaterial({
  color: 0x7fffd4,
  size: 10,
});

const focusMat = new PointsMaterial({
  color: 0x7fff00,
  size: 15,
});

const geo = new BufferGeometry();
geo.setFromPoints([new Vector3(0, 0, 0)]);

export class Point2D extends View2D {
  private readonly point = new Points(geo, normalMat);

  constructor(pos?: Vector2) {
    super();
    this.add(this.point);
    if (pos) {
      this.position.x = pos.x;
      this.position.y = pos.y;
    }
  }

  public onFoucus(isFocus: boolean) {
    if (isFocus !== this.isFocus) {
      this.isFocus = isFocus;
      this.point.material = isFocus ? focusMat : normalMat;
    }
  }
}
